
package com.futuremind.recyclerviewfastscroll;

import ohos.agp.components.Component;
import ohos.agp.components.element.Element;

/*** Created by mklimczak on 31/07/15.
 * @since 2021-04-10
 */
public class Utils {
    private Utils() {
    }

    /**
     * 控件在其整个屏幕上的坐标位置
     *
     * @param view
     * @return Y轴位置
     */
    public static float getViewRawY(Component view) {
        int[] location = new int[2];
        location[0] = 0;
        location[1] = ((Component) view.getComponentParent()).getLocationOnScreen()[1];
        return location[1];
    }

    /**
     * 控件在其整个屏幕上的坐标位置
     *
     * @param view
     * @return X轴位置
     */
    public static float getViewRawX(Component view) {
        int[] location = new int[2];
        location[0] = ((Component) view.getComponentParent()).getLocationOnScreen()[0];
        location[1] = 0;
        return location[0];
    }

    /**
     * 获取最小值
     *
     * @param min
     * @param max
     * @param value
     * @return 返回对比值
     */
    public static float getValueInRange(float min, float max, float value) {
        float minimum = Math.max(min, value);
        return Math.min(minimum, max);
    }

    /**
     * 设置背景
     *
     * @param component
     * @param element
     */
    public static void setBackground(Component component, Element element) {
        component.setBackground(element);
    }
}
